package net.edu_soft.ec.asset.controller;

import net.edu_soft.ec.asset.pojo.Advertising;
import net.edu_soft.ec.asset.service.AdvertisingService;
import net.edu_soft.ec.common.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@RestController
@RequestMapping("/advertise")
public class AdvertisingController {
    @Autowired
    private AdvertisingService advertisingService;

    /**
     * 创建轮播图
     * @param advertisingurl
     * @param name
     * @param sortOrder
     * @return
     */
    @RequestMapping(value = "/addAdvertise")
    public ResultVo addAdvertise(MultipartFile advertisingurl, String name, Integer sortOrder){
        if (advertisingService.addAdvertising(advertisingurl,name,sortOrder)!=1){
            return ResultVo.failed(201,"操作失败",null);
        }
        return ResultVo.succeed("ok",null);
    }

    /**
     * 获取轮播
     * @return
     */
    @RequestMapping(value = "/getAdvertise")
    public ResultVo getAdvertise(){
        List<Advertising> advertisingList=advertisingService.selectAll();
        return ResultVo.succeed("ok",advertisingList);
    }

    /**
     * 修改轮播图
     * @param advertising
     * @param advertisingurl
     * @return
     */
    @RequestMapping(value = "/updataAdvertise")
    public ResultVo updataAdvertise(Advertising advertising,MultipartFile advertisingurl){
        if (advertisingService.upDateAdvertising(advertising,advertisingurl)!=1){
            return ResultVo.failed(201,"操作失败",null);
        }
        return ResultVo.succeed("ok",null);
    }

    /**
     * 删除轮播
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleAdvertise")
    public ResultVo deleAdvertise(Integer id){
        if (advertisingService.deleteAdvertising(id)!=1){
            return ResultVo.failed(201,"操作失败",null);
        }
        return ResultVo.succeed("ok",null);
    }
}
